const ajax = {
    request(url,method,data = {}){
        const params = {method};

        if (method !== 'GET') {
            let form_data = new FormData;
            params.method = method;
            params._method = method;

            Object.keys(data).forEach(key => {
                form_data.append(key, data[key]);
            })

            params.body = form_data;
        }

        return fetch(`http://127.0.0.1/01_Module_C/api/v1/${url}?token=${store.auth.token}`,params).then(response => response.json().then(data=>{
            if (response.status !== 200) Bus.$emit('m',data.msg);
            return {status:response.status,data:data};
        }))
    },
    get(url){
        return this.request(url,'GET');
    },
    post(url,data={}){
        return this.request(url,'POST',data);
    },
    patch(url,data={}){
        return this.request(url,'PATCH',data);
    },
    delete(url,data={}){
        return this.request(url,'DELETE',data);
    },
};